package cn.com.eado.crm.v.fragment


import android.util.Log
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import cn.com.eado.crm.R
import cn.com.eado.crm.databinding.FragmentWeeklyDetailBinding
import cn.com.eado.crm.model.LoadStatus
import cn.com.eado.crm.model.RetryCallback
import cn.com.eado.crm.vm.CompanyViewModel
import cn.com.eado.preado.app.utils.autoCleared
import kotlinx.android.synthetic.main.fragment_weekly_detail.*

/**
 * A simple [Fragment] subclass.
 */
class WeeklyDetailFragment : BaseBindingFragment<FragmentWeeklyDetailBinding>(R.layout.fragment_weekly_detail) {

    private var vm by autoCleared<CompanyViewModel>()
//    private var adapter by autoCleared<RVCompanyAdapter>()

    override fun initTheFragment() {
        initView()
        initViewModel()
        initBinding()
        loadData()
    }

    private fun initView() {
        initTitleBar()
//        initRecyclerView()
    }

    private fun initTitleBar() {
        val title = arguments?.getString("name")?:"XXX管理"
        titleBar7.setTitle(title)
    }


    private fun initViewModel(){
        vm = ViewModelProviders.of(this).get(CompanyViewModel::class.java)
//        vm.result.observe(this, Observer {
//            if (it.status == LoadStatus.SUCCESS){
////                Log.e("tag", "it=${it.data}")
//            }
//        })
    }

    private fun initBinding(){
        binding.lifecycleOwner = viewLifecycleOwner
//        binding.result = vm.result
        binding.callback = object : RetryCallback {
            override fun retry() {
                vm.refresh()
            }
        }
    }

    private fun loadData(){
        vm.setLoadCompany(true)
    }


}
